import axios from 'axios';

export interface BaseInfoModel {
  activityName: string;
  channelType: string;
  promotionTime: string[];
  promoteLink: string;
}
export interface ChannelInfoModel {
  advertisingSource: string;
  advertisingMedia: string;
  keyword: string[];
  pushNotify: boolean;
  advertisingContent: string;
}

export type UnitChannelModel = BaseInfoModel & ChannelInfoModel;

export function submitChannelForm(data: UnitChannelModel) {
  return axios.post('/api/channel-form/submit', { data });
}

// // 正确的数据传递方式和函数结构
// export function getMappings(data: fileIdModel) {
//   return axios.post('/api/uplods', { data });
// }

// export interface fileIdModel {
//   fileId: number;
// }

// 使用 async/await 重写函数，直接传递 {fileId: number} 结构
export async function getMappings(data) {
  try {
    const response = await axios.post(
      'http://101.35.43.81:8111/api/get-mappings',
      data
    ); // 直接传递 data
    console.log(response.data);
    return response.data; // 直接返回处理过的数据
  } catch (error) {
    // 错误处理
    console.error('Failed to get mappings:', error);
    throw error; // 将错误向上抛出
  }
}
